@extends('layouts.public')

@section('head')
    <link rel="stylesheet" href="{{cdn('js/plugins/webuploader/single.css')}}">
    <style>
        .items{
            margin-bottom:15px;
        }
    </style>
@endsection

@section('bodyattr')class="gray-bg"@endsection

@section('body')
    <div class="wrapper wrapper-content">
        <div class="row m-b">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li><a href="{{route('admin.sign.signs')}}">签到列表</a></li>
                        <li @if(!isset($user))class="active"@endif><a href="{{route('admin.sign.signs.add')}}">签到规则</a></li>
                        @if(isset($user))
                            <li class="active"><a href="{{route('admin.sign.signs.add')}}">编辑签到规则</a></li>@endif
                    </ul>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form action="{{route('admin.sign.signs.save')}}" method="post" class="form-horizontal ajaxForm">
                            <input type="hidden" name="id" value="{{$user->id or 0}}"/>
                           
                            <div class="form-group">
                                <label class="col-sm-2 control-label">每天签到积分</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" required name="score" @if(isset($user)) value="{{$user->score or ''}}"placeholder="请填写每天签到获取积分" @endif autocomplete="off"/>
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-sm-2 control-label">签到规则</label>
                                <div class="col-sm-10">
                                    <textarea name="content" id="content">{{$user->content or ''}}</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">是否允许补签</label>
                                <div class="col-sm-10">
                                    <div class="input-group m-t-xs-2">
                                        <input type="radio" name="is_sign" value="1"
                                               @if ((isset($user->is_sign) ? $user->is_sign : '') != '0') checked="checked"@endif/>允许
                                        <input type="radio" name="is_sign" value="0"
                                               @if ((isset($user->is_sign) ? $user->is_sign : '') == '0') checked="checked"@endif/>不允许
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">可补签天数</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="unsign_day" >
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">保存</button>
                                    <button class="btn btn-white" type="button" id="backBtn">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script src="{{cdn('js/plugins/ueditor/ueditor.config.js')}}"></script>
    <script src="{{cdn('js/plugins/ueditor/ueditor.all.min.js')}}"></script>
    <script src="{{cdn('js/plugins/ueditor/lang/zh-cn/zh-cn.js')}}"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            var ue = UE.getEditor('content');

            ue.ready(function () {
                ue.execCommand('serverparam', {
                    '_token': '{{csrf_token()}}',
                    'filetype': 'FT_ARTICLE_DESC',
                    'itemid': '{{$user->id or 0}}'
                });
            });
            $('#add_options').click(function () {
                var str= '<div class="row items">\n' +
                    '                    <div class="col-sm-6">\n' +
                    '                    <input type="text"  class="form-control" name="size_name[]" required placeholder="请输入商品型号">\n' +
                    '                    </div>\n' +
                    '                    <div class="col-sm-4">\n' +
                    '                    <input type="text"  class="form-control" name="size_num[]" required  placeholder="请输入商品数量">\n' +
                    '                    </div>\n' +
                    '                    <div class="btn btn-default des">-</div>\n' +
                    '                    </div>';
                $('#options').append(str);
                $('.des').click(function () {
                    $(this).parent().remove()
                })

            })
            $('.des').click(function () {
                $(this).parent().remove()
            })
        });
    </script>
    <script src="{{cdn('js/plugins/webuploader/webuploader.nolog.min.js')}}"></script>
    <script src="{{cdn('js/plugins/webuploader/webuploader_public.js')}}"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            singleUpload({
                _token: '{{csrf_token()}}',
                type_key: 'FT_ARTICLE_IMG',
                item_id: '{{$user->id or 0}}',
                pick: 'filePicker',
                boxid: 'imgupload',
                file_path: 'default_img',
                file_id: 'file_id'
            });
            $('#imgupload').find('.img-div>span').click(function () {
                sUploadDel($(this), 'default_img');
            });
        });
    </script>
@endsection
